<!-- 投标申请 -->
<template>
	<view class="page">
		<u--form
			labelPosition="top"
			:model="model"
			ref="ErpOmcProjectApplyForm"
			:rules="rules"
			labelWidth="auto"
			:labelStyle="{
				fontSize: '14px',
				color: '#B2B2B2',
				lineHight: '20px'
			}"
		>
			<view class="basic-style">
				<u-form-item
					label="单据编号"
					prop="tenderCode"
					:borderBottom="false"
					required
				>
					<u--input
						disabled
						placeholder="请输入单据编号"
						v-model="model.tenderCode"
					></u--input>
				</u-form-item>
				<u-form-item
					label="日期"
					prop="createTime"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.createTime"
						disabled
						placeholder="请选择日期"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="申请人"
					prop="proposer"
					:borderBottom="false"
					required
				>
					<h-select-person-input
						style="width: 100%"
						disabled
						v-model="model.proposer"
						placeholder="请选择申请人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.proposer"
					></h-select-person-input>
				</u-form-item>
				<u-form-item
					label="申请部门"
					prop="proposerDeptId"
					:borderBottom="false"
					required
				>
					<h-select-depart-input
					  disabled
					  v-model="model.proposerDeptId"
					  :departName="model.proposerDeptText"
					  placeholder="请选择部门"
					  border="surround"
					  style="width: 100%"
					  suffixIcon="arrow-down-fill"
					  :suffixIconStyle="{ color: '#B2B2B2' }"
					  :title.sync="model.proposerDeptText"
					  @detail="onProposerDeptDetail"
					></h-select-depart-input>
				</u-form-item>
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">基本信息</view>
					<u-line :length="120"></u-line>
				</view>
				<u-form-item
					v-if="model.applyType == '2'"
					label="关联投标档案"
					prop="tenderFinalId"
					:borderBottom="false"
				>
					<h-select-omc-project-tender-input
						v-model="model.tenderFinalId"
						style="width: 100%"
						:data-isolation="'tender_person'"
						:data-type="'emp'"
						placeholder="请选择关联投标档案"
						objectField="model.tenderFinalId"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						@input="tenderFinalChange"
					></h-select-omc-project-tender-input>
				</u-form-item>
				
				<u-form-item
					label="项目名称"
					prop="prepareProjectId"
					:borderBottom="false"
					required
				>
					<h-select-project-input
					  ref="projectSelect"
					  :disabled="model.applyType == '2'"
					  v-model="model.prepareProjectId"
					  style="width: 100%"
					  placeholder="请选择项目名称"
					  objectField="model.prepareProjectId"
					  border="surround"
					  suffixIcon="arrow-down-fill"
					  :suffixIconStyle="{ color: '#B2B2B2' }"
					  @input="selectProject"
					  :use-type="'tender'"
					  :data-type="'username'"
					  :is-bidding="'1'"
						:queryOmcPrepareProjectList="true"
					  :tenderStatus="'0'"
					></h-select-project-input>
				</u-form-item>
				<u-form-item
					label="项目承接人"
					prop="undertaker"
					:borderBottom="false"
					required
				>
					<h-select-person-input
						style="width: 100%"
						v-model="model.undertaker"
						placeholder="请选择项目承接人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.undertaker"
					></h-select-person-input>
				</u-form-item>
				<u-form-item
					label="业绩归属年度"
					prop="year"
					:borderBottom="false"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.year" 
						placeholder="请选择业绩归属年度" 
						dictName="yjgsnd" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="项目地址"
					prop="projectAddress"
					:borderBottom="false"
					required
				>
					<h-select-address-input
						style="width: 100%"
						v-model="model.projectAddress"
						placeholder="请选择项目地址"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-select-address-input>
				</u-form-item>
				<u-form-item
					label="项目详细地址"
					prop="detailedAddress"
					:borderBottom="false"
					required
				>
					<u--input
						placeholder="请输入项目详细地址"
						v-model="model.detailedAddress"
					></u--input>
				</u-form-item>
				<u-form-item
					label="经营团队"
					prop="businessTeam"
					:borderBottom="false"
					required
				>
					<h-select-team-input
					   @input="changeBusinessCompany"
						style="width: 100%;"
						v-model="model.businessTeam"
						objectField="model.businessTeam"
						placeholder="请选择经营团队"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						:tdlx="1"
					></h-select-team-input>
				</u-form-item>
				<!-- <u-form-item
				label="经营公司"
				prop="businessCompanyId"
				:borderBottom="false"
				required>
				<h-select-company-input
					disabled
					style="width: 100%"
					v-model="model.businessCompanyId"
					border="surround"
					placeholder="请选择经营公司"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
					objectField='model.businessCompanyId'
				></h-select-company-input>
              </u-form-item> -->
				<u-form-item
					label="报名截止时间"
					prop="entriesEndDate"
					:borderBottom="false"
				>
					<h-time-select
						:disabled="editFildDisabled"
						v-model="model.entriesEndDate"
						placeholder="请选择报名截止时间"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						mode="datetime"
					></h-time-select>
				</u-form-item>
				<u-form-item
					label="投标截止时间"
					prop="tenderEndDate"
					:borderBottom="false"
				>
					<h-time-select
						:disabled="editFildDisabled"
						v-model="model.tenderEndDate"
						placeholder="请选择投标截止时间"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						mode="datetime"
					></h-time-select>
				</u-form-item>
				<u-form-item
					label="业主单位"
					prop="ownerUnit"
					:borderBottom="false"
					required
				>
					<h-select-customer-input
						style="width: 100%"
						v-model="model.ownerUnit"
						commercialType= "1"
						border="surround"
						placeholder="请选择业主单位"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField = 'model.ownerUnit'
						@input="onCustomerChange"
					></h-select-customer-input>
				</u-form-item>
				<u-form-item
					label="业主联系人"
					prop="ownerLinkman"
					:borderBottom="false"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.ownerLinkman" 
						placeholder="请选择业主联系人" 
						:dictName="cust_lxr" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
						@change="lxrChange"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="业主联系方式"
					prop="ownerTel"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.ownerTel"
						placeholder="请输入业主联系方式"
						border="surround"
					></u--input>
				</u-form-item>
				
				<u-form-item
					label="招标方式"
					prop="biddingMethod"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.biddingMethod" 
						placeholder="请选择招标方式" 
						dictName="bidding_method"
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="招标控制价(元)"
					prop="controlPrice"
					:borderBottom="false"
					ref="item1"
				>
					<h-money-input
						:disabled="editFildDisabled"
						placeholder="请输入招标控制价"
						v-model="model.controlPrice"
					></h-money-input>
				</u-form-item>
				<u-form-item
					type="number"
					label="标书费(元)"
					prop="entryFee"
					:borderBottom="false"
					ref="item1"
				>
					<h-money-input
						:disabled="editFildDisabled"
						placeholder="请输入标书费"
						v-model="model.entryFee"
					></h-money-input>
				</u-form-item>
				<u-form-item
					label="投标保证金(元)"
					prop="tenderBond"
					:borderBottom="false"
					ref="item1"
				>
					<h-money-input
						:disabled="editFildDisabled"
						placeholder="请输入投标保证金"
						v-model="model.tenderBond"
					></h-money-input>
				</u-form-item>
				<u-form-item
					label="项目公示信息"
					prop="projectPublicity"
					:borderBottom="false"
					ref="item1"
				>
					<u--textarea
						v-model="model.projectPublicity"
						:confirmType="null"
						count
						placeholder="请输入项目公示信息"
						:maxlength="500"
					></u--textarea>
				</u-form-item>
				<u-form-item
					label="投标内容概要"
					prop="tenderContent"
					:borderBottom="false"
					ref="item1"
				>
					<u--textarea
						v-model="model.tenderContent"
						:confirmType="null"
						count
						placeholder="请输入投标内容概要"
						:maxlength="500"
					></u--textarea>
				</u-form-item>
			</view>
			
			<view class="basic-style">
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">投标单位信息</view>
					<u-line :length="120"></u-line>
				</view>
				<u-form-item
					label="投标部门"
					prop="tenderDept"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-select-depart-input
						v-model="model.tenderDept"
						:departName="model.tenderDept_dictText"
						placeholder="请选择投标部门"
						border="surround"
						style="width: 100%;"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						@detail="ontenderDeptDetail"
					></h-select-depart-input>
				</u-form-item>
				<u-form-item
					label="投标编制人"
					prop="tenderPerson_dictText"
					:borderBottom="false"
					ref="item1"
				>
					<u--input
						v-model="model.tenderPerson_dictText"
						disabled
						placeholder="请选择投标编制人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="投标单位"
					prop="tenderUnit"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-select-company-input
						style="width: 100%;"
						v-model="model.tenderUnit"
						objectField="model.tenderUnit"
						placeholder="请选择投标单位"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-select-company-input>
				</u-form-item>
				<u-form-item
					label="是否需要协调"
					prop="needHelp"
					:borderBottom="false"
					ref="item1"
				>
					<h-dict-radio disabled v-model="model.needHelp" dictName="YES_OR_NO"></h-dict-radio>
				</u-form-item>
				<u-form-item
					v-if="model.needHelp && model.needHelp == 1"
					label="协同人员（多选）"
					prop="helperIds_dictText"
					:borderBottom="false"
					ref="item1"
				>
					<u--input
						v-model="model.helperIds_dictText"
						disabled
						placeholder="请选择协同人员（多选）"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="备注"
					prop="remarks"
					:borderBottom="false"
					ref="item1"
				>
					<u--textarea :maxlength="500" disabled confirmType="done" count v-model="model.remarks" placeholder="请输入备注" ></u--textarea>
				</u-form-item>
			</view>
		</u--form>
		
		<!-- 附件 -->
		<view class="basic-style">
			<view class="basic-title-center">
				<u-line :length="120"></u-line>
				<view class="">招标文件</view>
				<u-line :length="120"></u-line>
			</view>
			<view class="warning">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
			<view class="" style="width: 100%;">
				<h-upload-file v-model="model.tenderFile" :isIcon="false" ></h-upload-file>
				<file-list v-if="model.tenderFile" v-model="model.tenderFile" :isDelete="true"></file-list>
			</view>
		</view>
		<view class="basic-style">
			<view class="basic-title-center">
				<u-line :length="105"></u-line>
				<view class="">业务分类</view>
				<u-line :length="105"></u-line>
			</view>
			<ErpOmcTenderClassifyForm @ok="onInforList" ref="projectTaskFormConfig" :assignedAmount="model.controlPrice" :dataList="dataSource"></ErpOmcTenderClassifyForm>
		</view>
		<view class="space-x-1 px-1 btn_position">
			<u-button :disabled="isSubmit" type="primary" :plain="true" text="保存" @click="onDrafts"></u-button>
			<u-button :disabled="isSubmit"  type="primary"  text="保存并提交" @click="onSubmit"></u-button>
		</view>
		<view style="height: 100rpx;"></view>
		<u-toast ref="uToast"></u-toast>
		<ProcessNodeConfiguration ref="processConfig" @ok="onOk"></ProcessNodeConfiguration>
	</view>
</template>
<!-- 
	参数说明：applyType：1 => 投标申请，2 => 投标申请变更
 -->
<script>
import fileList from '@/pages/synergy/components/fileList.vue'
import ErpOmcTenderClassifyForm from './components/ErpOmcTenderClassifyForm.vue' // 业务分类组件
import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue' // 流程节点配置人员选择弹窗
import specialHttp from '@/utils/request/specialIndex' // 特殊请求方式，直接返回res
import http from '@/utils/request/index.js' // 特殊请求方式，直接返回res
import {
	generatedFormNumber, // 获取单据编号
	erpOmcCustomerManagerContactId, // 获取联系方式
	erpOmcTenderAdd, // 添加
	erpOmcTenderQueryEdit, // 编辑
	erpOmcTenderQueryById, // 详情
	erpOmcProjectApplyQueryByProjectId ,// 获取业务分类信息列表
	erpOmcProjectApplyQueryTenderResultByEntity,
	erpOmcProjectApplyQueryTenderServiceListByTenderId,
	queryByIdTenderService
} from '@/api/index.js'
import moment from 'moment'
import {
	BASE_URL
} from '@/utils/baseUrl.js'
import { convertCurrency } from '@/utils/MoneyConvert' // 金额大写转换
export default {
	components: {
		fileList,
		ErpOmcTenderClassifyForm,
		ProcessNodeConfiguration
	},
	data() {
		return {
			isFinalProjectId: false, // 用于判断编辑的时候不执行预立项详情
			isSubmit: false,
			model: {
				applyType: '1',
				businessCompanyId: '', // 经营公司
				tenderCode: '', //单据编号
				createTime: '', // 申请时间
				proposer: '', // 申请人
				proposerDeptId: '', // 申请部门
				tenderFinalId: '', // 投标档案
				prepareProjectId: '', // 项目名称
				undertaker: '', // 项目承接人
				year: '', // 业绩发归属年度
				projectAddress: '', // 项目所在地址
				detailedAddress: '', // 项目详细地址
				businessTeam: '', // 经营团队
				businessCompanyId: '', // 经营公司
				entriesEndDate: '', // 报名截止时间
				tenderEndDate: '', // 投标截止时间
				ownerUnit: '', // 业主单位
				ownerLinkman: '', // 联系人
				ownerTel: '', // 联系方式
				biddingMethod: '', // 招标方式
				controlPrice: '', // 招标控制价
				entryFee: '', // 标书费
				tenderBond: '', // 投标保证金
				projectPublicity: '', // 项目公式信息
				tenderContent: '', // 投标内容概要
				
				// 投标单位信息
				tenderDept: '', 
				tenderPerson: '',
				tenderUnit: '',
				needHelp: '',
				helperIds: '',
				remarks: '',
				
				tenderFile: '', // 招标文件
			},
			cust_lxr: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0',
			id: '', // 详情id值
			dataSource: [], // 业务分类信息列表
			rules: {
				tenderCode: [
					{ required: true, message: '请输入单据编号!', trigger: ['change','blur'], },
				],
				createTime: [
					{ required: true, message: '请选择日期!', trigger: ['change','blur'], },
				],
				proposer: [
					{ required: true, message: '请选择申请人!', trigger: ['change','blur'], },
				],
				proposerDeptId: [
					{ required: true, message: '请选择申请部门!', trigger: ['change','blur'], },
				],
				
				tenderUnit: [
					{ required: true, message: '请选择投标单位!', trigger: ['change','blur'], },
				],
				tenderPerson: [
					{ required: true, message: '请选择投标编制人!', trigger: ['change','blur'], },
				],
				tenderDept: [
					{ required: true, message: '请选择投标部门!', pattern: '[^ \x22]+', trigger: ['change','blur'] },
				],
				prepareProjectId: [
					{ required: true, message: '请选择预立项项目!', trigger: ['change','blur'], },
				],
				undertaker: [
					{ required: true, message: '请选择承接人!', trigger: ['change','blur'], },
				],
				year: [
					{ required: true, message: '请选择业绩归属年度!', trigger: ['change','blur'], },
				],
				projectAddress: [
				  { required: true, message: '请选择项目地址!', trigger: ['change','blur'], },
				],
				detailedAddress: [
				  { required: true, message: '请输入项目详细地址!', trigger: ['change','blur'], },
				],
				businessTeam: [
				  { required: true, message: '请选择经营团队!', trigger: ['change','blur'], },
				],
				ownerUnit: [
				  { required: true, message: '请选择业主单位!', trigger: ['change','blur'], },
				],
				ownerLinkman: [
				  { required: true, message: '请选择联系人!', trigger: ['change','blur'], },
				],
				biddingMethod: [
				  { required: true, message: '请选择招标方式!', trigger: ['change','blur'], },
				],
				ownerTel: [
					{ required: true, message: '请输入业主联系人!', trigger: ['change', 'blur'], },
					{
						// 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
							// 返回true表示校验通过，返回false表示不通过
							var reg = /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/
							if (reg.test(value)) {
								return true
							} else {
								return false
							}
							// return uni.$u.test.mobile(value);
						},
						message: '请输入正确的联系电话!',
						// 触发器可以同时用blur和change
						trigger: ['change','blur'],
					}
				],
				// controlPrice: [
				// 	{ 
				// 		validator: (rule, value, callback) => {
				// 			// 上面有说，返回true表示校验通过，返回false表示不通过
				// 			// uni.$u.test.mobile()就是返回true或者false的
				// 			return uni.$u.test.amount(value);
				// 		},
				// 		message: '请输入正确的金额!',
				// 		// 触发器可以同时用blur和change
				// 		trigger: ['blur'],
				// 	}
				// ],
				// entryFee: [
				// 	{
				// 		validator: (rule, value, callback) => {
				// 			// 上面有说，返回true表示校验通过，返回false表示不通过
				// 			// uni.$u.test.mobile()就是返回true或者false的
				// 			return uni.$u.test.amount(value);
				// 		},
				// 		message: '请输入正确的金额!',
				// 		// 触发器可以同时用blur和change
				// 		trigger: ['blur'],
				// 	}
				// ],
				// tenderBond: [
				// 	{
				// 		validator: (rule, value, callback) => {
				// 			// 上面有说，返回true表示校验通过，返回false表示不通过
				// 			// uni.$u.test.mobile()就是返回true或者false的
				// 			return uni.$u.test.amount(value);
				// 		},
				// 		message: '请输入正确的金额!',
				// 		// 触发器可以同时用blur和change
				// 		trigger: ['blur'],
				// 	}
				// ]
			},
			
			
			//代码生成后需手动设置流程编码
			flowCode: 'dev_erp_omc_tender_002',
			formUrl: 'erp/omc/tender/modules/ErpOmcTenderDetailForm',
			beanName: 'erpOmcTenderServiceImpl',
			processId: '1557902030017896449',
			formUrlMobile: '/pages/synergy/erpOmcTenderList',
		};
	},
	
	computed: {
	    // 投标审核需要动态禁用的状态字段
	    editFildDisabled() {
	      // 新增和变更的时候只能看不能填
	      return true
	    },
	  },
	onLoad(options) {
		this.id = options.id || ''
		if (options.id) {
			// 编辑
			this.edit(options.id)
		} else {
			// 添加
			this.add()
		}
		if (options.applyType) {
			this.model.applyType = options.applyType
		}
		
	},
	onReady() {
		// 修改当前页面的标题
		var title = '投标申请'
		if (this.model.applyType == 2) {
			title = '投标变更'
		} else {
			title = '投标申请'
		}
		uni.setNavigationBarTitle({
			title: title
		});
	},
	methods: {

		changeBusinessCompany(val){
      this.model.businessCompanyId = val.belongCompanyId
                        
      },
		// 编辑
		edit(id) {
			// 获取详情
			this.getDetail(id)
			this.getQueryTenderServiceList(id)
		},
		getQueryTenderServiceList (id) {
			http.get('/api/erp/omc/tender/erpOmcTenderService/queryTenderServiceListByTenderId', { id }).then((res) => {
				if (res.success) {
					this.dataSource = res.result.records || res.result
				}
			})
		},
		// 获取详请
		getDetail (id) {
			erpOmcTenderQueryById({ id }).then(res => {
				if (res.success) {
					this.cust_lxr = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + res.result.ownerUnit + '\'';
					this.model = {...res.result};
					this.model.ownerLinkman = res.result.ownerLinkman
					this.model.year = this.model.year + ''
					this.model.ownerTel = res.result.ownerTel
					if (this.model.controlPrice) {
						this.model.controlPrice = Number(this.model.controlPrice).toFixed(2)
					}
					
				}
			})
		},
		
		// 获取流程列表
		getProcessList (id) {
			if (this.isSubmit) {
				http.get('/api/erp/omc/project/erpOmcProject/checkProjectTenderStatus', { id: this.model.prepareProjectId, type: this.model.applyType }).then(res => {
					if (res.success) {
						http.get('/api/erp/omc/contractmanager/erpOmcContractManagerFinal/totalCount', { xmmc: this.model.prepareProjectId, htlx: 1 }).then(res => 						{
							if (res.success) {
								if (res.result <= 0){
									//校验通过
									this.$refs.processConfig.showPopup = true
									this.$refs.processConfig.formUrl = this.formUrl
									this.$refs.processConfig.formUrlMobile = this.formUrlMobile
									this.$refs.processConfig.flowCode = this.flowCode
									this.$refs.processConfig.edit(id, this.processId, this.beanName)
								}else{
									//校验不通过
									this.$refs.uToast.show({
										message: '该项目已签收款合同，无法进行投标!',
										complete () {
											if (getCurrentPages().length > 1) {
												uni.navigateBack()
											} else {
												uni.reLaunch({
													url: '/pages/home/home'
												})
											}
											
										}
									})
								}
							} else {
								this.$refs.uToast.show({
									message: res.message,
									complete () {
										if (getCurrentPages().length > 1) {
											uni.navigateBack()
										} else {
											uni.reLaunch({
												url: '/pages/home/home'
											})
										}
										
									}
								})
							}
						})
					} else {
						this.$refs.uToast.show({
							message: res.message,
							complete () {
								if (getCurrentPages().length > 1) {
									uni.navigateBack()
								} else {
									uni.reLaunch({
										url: '/pages/home/home'
									})
								}
								
							}
						})
					}
				})
			}
		},
		
		// 获取分类信息列表
		getErpOmcProjectTaskList (id) {
			specialHttp.get('/api/erp/omc/project/erpOmcProjectTask/listById', { id: id }).then(res => {
				if (res.length > 0) {
					this.dataSource = res || res.result || []
					this.dataSource.forEach(ele => {
						ele.serviceType = ele.categoryCode
						ele.serviceName = ele.categoryName
					});
				}
			})
		},
		
		// 投标部门详情
		ontenderDeptDetail(item) {
			var title = ''
			if (item && item.length) {
				if (item[0].parents && item[0].parents.length) {
					title = item[0].parents[0].name + '/' + item[0].name
				} else {
					title = item[0].name
				}
			}
		  this.model.tenderDept_dictText = title
		},
		onProposerDeptDetail (item) {
			var title = ''
			if (item && item.length) {
			  item.map((value, index) => {
			    title = value.name + ',' + title
			  })
			  title = title.substring(0, title.lastIndexOf(','))
			}
			this.model.proposerDeptText = title
		},
		
		//选择项目名称
		async selectProject(project) {
			this.cust_lxr = await 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + project.ownerUnit + '\'';
			this.$set(this.model, 'prepareProjectId', project.id)
			this.$set(this.model, 'projectName', project.projectName)
			this.$set(this.model, 'bpmBizTitle', project.projectName + '-' + uni.getStorageSync('userInfo').employee.name + '-' + this.model.tenderCode)// 标题
			this.$set(this.model, 'undertaker', project.undertaker)
			this.$set(this.model, 'year', project.year + '')
			this.$set(this.model, 'projectAddress', project.areaCode)
			this.$set(this.model, 'detailedAddress', project.projectAddress)
			this.$set(this.model, 'businessTeam', project.oldTeamId ? project.oldTeamId : project.teamName)
			this.$set(this.model, 'businessCompanyId', project.businessCompanyId)
			this.$set(this.model, 'ownerUnit', project.ownerUnit)
			this.$set(this.model, 'ownerTel', project.contactTel)
			this.getErpOmcProjectTaskList(project.id)
			this.$set(this.model, 'ownerLinkman', project.contacts)
			
		},
		
		// 点击预立项
		prepareProjectClick () {
			this.isFinalProjectId = true
		},
		
		
		// 投标档案选择
		tenderFinalChange(tenderFinal) {
			// this.model = Object.assign(this.model, obj);
			this.$set(this.model, 'undertaker', tenderFinal.undertaker)
			this.$set(this.model, 'year', tenderFinal.year + '')
			// this.$set(this.model,'tenderFinalId',tenderFinal.id)
			this.$set(this.model, 'tenderFinalCode', tenderFinal.tenderCode)
			this.$set(this.model, 'projectName', tenderFinal.projectName)
			this.$set(this.model, 'prepareProjectId', tenderFinal.prepareProjectId)
			this.$set(this.model, 'projectAddress', tenderFinal.projectAddress)
			this.$set(this.model, 'detailedAddress', tenderFinal.detailedAddress)
			this.$set(this.model, 'businessTeam', tenderFinal.businessTeam)
			this.$set(this.model, 'businessCompanyId', tenderFinal.businessCompanyId)
			this.$set(this.model, 'entriesEndDate', tenderFinal.entriesEndDate)
			this.$set(this.model, 'tenderEndDate', tenderFinal.tenderEndDate)
			this.$set(this.model, 'ownerUnit', tenderFinal.ownerUnit)
			this.$set(this.model, 'ownerLinkman', tenderFinal.ownerLinkman)
			this.$set(this.model, 'ownerTel', tenderFinal.ownerTel)
			this.$set(this.model, 'biddingMethod', tenderFinal.biddingMethod)
			this.$set(this.model, 'controlPrice', tenderFinal.controlPrice)
			this.$set(this.model, 'entryFee', tenderFinal.entryFee)
			this.$set(this.model, 'tenderBond', tenderFinal.tenderBond)
			this.$set(this.model, 'projectPublicity', tenderFinal.projectPublicity)
			this.$set(this.model, 'tenderContent', tenderFinal.tenderContent)
			this.$set(this.model, 'tenderFile', tenderFinal.tenderFile)
			this.$set(this.model, 'isTeamwork', tenderFinal.isTeamwork)
			// 投标部门
			this.$set(this.model, 'tenderDept', tenderFinal.tenderDept)
			this.$set(this.model, 'tenderDept_dictText', tenderFinal.tenderDept_dictText)
			// 投标编制人
			this.$set(this.model, 'tenderPerson', tenderFinal.tenderPerson)
			this.$set(this.model, 'tenderPerson_dictText', tenderFinal.tenderPerson_dictText)
			// 投标单位
			this.$set(this.model, 'tenderUnit', tenderFinal.tenderUnit)
			// 是否需要协调
			this.$set(this.model, 'needHelp', tenderFinal.needHelp == null ? '': tenderFinal.needHelp )
			// fix:BUG#4985 投标变更-备注字段信息未带出 start
			this.$set(this.model, 'remarks', tenderFinal.remarks)
			// fix:BUG#4985 投标变更-备注字段信息未带出 end
			// 协同人员（多选）
			this.$set(this.model, 'helperIds', tenderFinal.helperIds)
			this.$set(this.model, 'helperIds_dictText', tenderFinal.helperIds_dictText)

			this.$set(this.model, 'teamworkPerson', tenderFinal.teamworkPerson)
			this.cust_lxr = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
			// 子表（立项）-》业务分类子表（投标申请）
			erpOmcProjectApplyQueryTenderServiceListByTenderId({ id: tenderFinal.id }).then((res) => {
				if (res.success) {
					this.dataSource = res.result
				}
			})
			// this.convertMoneyBlur2(tenderFinal.controlPrice)
			this.$refs.ErpOmcProjectApplyForm.clearValidate() // 清空校验结果
		},
		
		// 添加
		add() {
			this.getGeneratedFormNumber()
			this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss'); // 申请时间
			this.model.proposer = uni.getStorageSync('userInfo').empId; //申请人
			this.model.proposerDeptId = uni.getStorageSync('userInfo').deptId; //申请部门
		},
		// 获取单据编号
		getGeneratedFormNumber() {
			generatedFormNumber({ prefix: 'TB', subSystemCode: '05' }).then(res => {
				if (res.success) {
					this.$set(this.model, 'tenderCode', res.result)
				}
			})
		},
		
		// 选择业主单位
		onCustomerChange () {
			this.cust_lxr = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
			this.$set(this.model, 'ownerLinkman', '')
			this.$set(this.model, 'ownerTel', '')
		},
		// 选择联系人
		lxrChange (val) {
			var params = {id: val}
			
			this.$set(this.model, 'ownerLinkman', val)
			erpOmcCustomerManagerContactId(params).then(res => {
				if (res.success) {
					let data = res.result.records || res.result
					this.$set(this.model, 'ownerTel', data.lxfs)
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		onInforList (item) {
			this.dataSource = item
		},
		
		// 点击提交
		onSubmit () {
			var that = this
			this.$refs.ErpOmcProjectApplyForm.validate().then(res => {
				if(res){
					this.isSubmit = true
					this.model.itemList = this.dataSource;
					let httpurl = '';
					if (!this.id) {
						httpurl = erpOmcTenderAdd;
					} else {
						httpurl = erpOmcTenderQueryEdit;
					}
					httpurl(this.model).then(res => {
						if (res.success) {
							this.$refs.uToast.show({
								message: res.message,
								type: 'default'
							})
							var that = this
							// 获取流程列表
							if (this.id) {
								this.getProcessList(this.id)
							} else {
								// 判断添加的时候是否有返回id值
								if (res.result) {
									this.getProcessList(res.result)
								}
								
							}
							
						} else {
							this.$refs.uToast.show({
								message: res.message,
								type: 'error'
							})
						}
					})
				}
			})
		},
		
		onDrafts() {
			var that = this
			this.isSubmit = true
			this.model.itemList = this.dataSource;
			let httpurl = '';
			if (!this.id) {
				httpurl = erpOmcTenderAdd;
			} else {
				httpurl = erpOmcTenderQueryEdit;
			}
			httpurl(this.model).then(res => {
				if (res.success) {
					var that = this
					this.$refs.uToast.show({
						message: res.message,
						type: 'default',
						complete () {
							that.isSubmit = false
							if (getCurrentPages().length > 1) {
								uni.navigateBack()
							} else {
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}
							
						}
					})
					
					
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		// 提交流程成功
		onOk () {
			this.$refs.uToast.show({
				message: '提交成功',
				type: 'success',
				complete () {
					if (getCurrentPages().length > 1) {
						uni.navigateBack()
					} else {
						uni.reLaunch({
							url: '/pages/home/home'
						})
					}
					
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
@import url("@/assets/inputStyle.scss");
</style>